package model;

import java.util.*;

public class MachineType {
	private long ID;
	private String name;
	private String description;

	/**
	 * Link between MachineType and SparePart is 0..* -------> 0..*
	 */
	private List<SparePart> spareParts;

	/**
	 * Link between MachineType and RepairType is 0..* -------> 0..*
	 */

	private List<RepairType> repairTypes;

	// link: MachineType 1--0...* Machine
	private List<Machine> machines;

	/**
	 * @param ID
	 * @param name
	 * @param description
	 * 
	 * @author Osahon Idehen
	 */

	public MachineType(long ID, String name, String description) {
		this.ID = ID;
		this.name = name;
		this.description = description;

		spareParts = new ArrayList<SparePart>();
		repairTypes = new ArrayList<RepairType>();
		machines = new ArrayList<Machine>();
	}

	/**
	 * @return the iD
	 * 
	 * @author Osahon Idehen
	 */
	public long getID() {
		return ID;
	}

	/**
	 * @param id
	 *            the iD to set
	 * 
	 * @author Osahon Idehen
	 */
	public void setID(long id) {
		ID = id;
	}

	/**
	 * @return the name
	 * 
	 * @author Osahon Idehen
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 * 
	 * @author Osahon Idehen
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 * 
	 * @author Osahon Idehen
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 * 
	 * @author Osahon Idehen
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	// link Methods start
	/**
	 * adds SpareParts to a MachineType
	 * 
	 * @author Osahon Idehen
	 */
	public void addSparePart(SparePart sparePart) {
		spareParts.add(sparePart);
	}

	/**
	 * removes a SparePart from a MachineType
	 * 
	 * @author Osahon Idehen
	 */
	public void removeSparePart(SparePart sparePart) {
		spareParts.remove(sparePart);
	}

	/**
	 * @return the spareParts
	 * 
	 * @author Osahon Idehen
	 */
	public List<SparePart> getSpareParts() {
		return spareParts;
	}

	/**
	 * adds a RepairType to a MachineType
	 * 
	 * @author Osahon Idehen
	 */
	public void addRepairType(RepairType repairType) {
		repairTypes.add(repairType);
	}

	/**
	 * removes a RepairType from the MachineType
	 * 
	 * @author Osahon Idehen
	 */
	public void removeRepairType(RepairType repairType) {
		repairTypes.remove(repairType);
	}

	/**
	 * @return the repairTypes
	 * 
	 * @author Osahon Idehen
	 */
	public List<RepairType> getRepairTypes() {
		return repairTypes;
	}

	/**
	 * Adds a Machine to this MachineType and sets the MachineType to the
	 * Machine.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public void addMachine(Machine machine) {
		if (!machines.contains(machine)) {
			machines.add(machine);
			machine.setMachineType(this);
		}
	}

	/**
	 * Removes the Machine from this MachineType and sets the MachineType to the
	 * Machine null.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public void removeMachine(Machine machine) {
		if (machines.contains(machine)) {
			machines.remove(machine);
			machine.setMachineType(null);
		}
	}

	/**
	 * @return the machines.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public List<Machine> getMachines() {
		return machines;
	}

	// link Methods end

	public String toString() {
		return ID + " " + name + " " + description;
	}
}